package com.empire.module.sporttery.controller.admin.football500yazdetail;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.CommonResult;
import com.empire.framework.common.util.object.BeanUtils;
import static com.empire.framework.common.pojo.CommonResult.success;

import com.empire.framework.excel.core.util.ExcelUtils;

import com.empire.framework.apilog.core.annotation.ApiAccessLog;
import static com.empire.framework.apilog.core.enums.OperateTypeEnum.*;

import com.empire.module.sporttery.controller.admin.football500yazdetail.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500yazdetail.Football500YazDetailDO;
import com.empire.module.sporttery.service.football500yazdetail.Football500YazDetailService;

@Tag(name = "管理后台 - 亚盘详情")
@RestController
@RequestMapping("/sporttery/football500-yaz-detail")
@Validated
public class Football500YazDetailController {

    @Resource
    private Football500YazDetailService football500YazDetailService;

    @PostMapping("/create")
    @Operation(summary = "创建亚盘详情")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-detail:create')")
    public CommonResult<Integer> createFootball500YazDetail(@Valid @RequestBody Football500YazDetailSaveReqVO createReqVO) {
        return success(football500YazDetailService.createFootball500YazDetail(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新亚盘详情")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-detail:update')")
    public CommonResult<Boolean> updateFootball500YazDetail(@Valid @RequestBody Football500YazDetailSaveReqVO updateReqVO) {
        football500YazDetailService.updateFootball500YazDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除亚盘详情")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-detail:delete')")
    public CommonResult<Boolean> deleteFootball500YazDetail(@RequestParam("id") Integer id) {
        football500YazDetailService.deleteFootball500YazDetail(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得亚盘详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-detail:query')")
    public CommonResult<Football500YazDetailRespVO> getFootball500YazDetail(@RequestParam("id") Integer id) {
        Football500YazDetailDO football500YazDetail = football500YazDetailService.getFootball500YazDetail(id);
        return success(BeanUtils.toBean(football500YazDetail, Football500YazDetailRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得亚盘详情分页")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-detail:query')")
    public CommonResult<PageResult<Football500YazDetailRespVO>> getFootball500YazDetailPage(@Valid Football500YazDetailPageReqVO pageReqVO) {
        PageResult<Football500YazDetailDO> pageResult = football500YazDetailService.getFootball500YazDetailPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, Football500YazDetailRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出亚盘详情 Excel")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-yaz-detail:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportFootball500YazDetailExcel(@Valid Football500YazDetailPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<Football500YazDetailDO> list = football500YazDetailService.getFootball500YazDetailPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "亚盘详情.xls", "数据", Football500YazDetailRespVO.class,
                        BeanUtils.toBean(list, Football500YazDetailRespVO.class));
    }

}